﻿$("#mainMenu").append("<li ><a href='Index.html' >首页</a></li>");
$("#mainMenu").append("<li ><a href='ScoreSearch.html' >成绩查询</a></li>");
$("#mainMenu").append("<li ><a href='ExzamSearch.html' >考试查询</a></li>");
$("#mainMenu").append("<li ><a href='ScoreEdit.html' >成绩录入</a></li>");
$("#mainMenu").append("<li ><a href='ExzamEdit.html' >考试编辑</a></li>");
$("#mainMenu").append("<li ><a href='Contact.html' >联系方式</a></li>");




//左侧导航js
function sidebarNavigate() {
    $(".sidebar-nav li").not(".nav-header").click(function () {
        $(".sidebar-nav li").not(".nav-header").removeClass("active");
        $(this).addClass('active');
    });
}
sidebarNavigate();

//禁用表单提交
$(document).ready(function () {
    //定义表单提交前与提交后的处理方法及超时相关
    $('form').submit(function () {
        return false;
    });
});

//获取option内容
function getConditOption(action, selectid) {
    var c = "#" + selectid;
    $.post("handler/ConditionHandler.ashx", { 'action': action }, function (data, status) {
        $(c).append(data);
        $(c).append("</option>");
    });
    //获取option内容
}

//prams：请求参数
//option:json格式，内容如下
//selectid：需要添加数据的htmlid
//idcolum：id列
//name：显示列
//func：回掉函数
function getConditByParams(prams, option, func) {
    $(selection).html("");
    var jsonop = eval(option);
    var selection = "#" + jsonop.selectid;
    $.post("handler/ConditionHandler.ashx", prams, function (data, status) {
        var content;
        if (data.Table.length == 0) {
            content = "";
        } else {
            $(data.Table).each(function (i, item) {
                content += "<option value=" + item[jsonop.idcolum] + ">";
                content += item[jsonop.name];
                content += ("</option>");
            });
        }
        $(selection).html(content);
        $(selection).change();
        func();
    }, "json");
}

//json参数添加
function createJson(jsondata, key, val) {
    // 如果 val 被忽略
    if (typeof val === "undefined") {
        // 删除属性
        delete jsondata[key];
    }
    else {
        // 添加 或 修改
        jsondata[key] = val;
    }
}



//创建空表
function tableNullCreate(tableid, thArgs) {
    $("#" + tableid).html("");
    $("#" + tableid).append("<thead>");
    var jsonArgs = eval(thArgs);
    $(jsonArgs).each(function (i, item) {
        $("#" + tableid).append("<th>" + item + "</th>");
    });
    $("#" + tableid).append("</thead>");
}

//生成完整表
function getFullTableRows2(tableid, jsondata, colums, idcolumn) {
    tableNullCreate(tableid, colums);

    var table = $("#" + tableid);
    colums = eval(colums);
    var content = "";
    content += "<tbody>";
    $(jsondata.Table).each(function (i, item) {
        console.log("i:" + i);

        content += "<tr exzamid='" + item[idcolumn] + "'>";

        $(colums).each(function (i2, item2) {
            content += "<td>" + item[item2] + "</td>";
        });
        content += "</tr>";

    });
    content += "</tbody>";
    table.append(content);

}

//生成完整表
function getFullTableRows(tableid, jsondata, colums) {
    getFullTableRows2(tableid, jsondata, colums, "");

}


//获取当前年份和学期
function getCurrentYearTerm() {
    var date = new Date();
    var year = date.getFullYear();
    var term = date.getMonth() <= 5 ? '上' : '下';
    var json = { 'year': year, 'term': term };
    var yterm = year + term;
    return yterm;
}

//在select下填充年份和日期
function getFourYearTerm(selectid) {
    var termSelect = $('#' + selectid);
    var date = new Date();
    var year = date.getFullYear();
    var term = date.getMonth() <= 5 ? '上' : '下';
    termSelect.html("");
    for (var i = 0; i < 4; i++) {
        termSelect.append("<option>" + year + "下</option>");
        termSelect.append("<option>" + year + "上</option>");
        year--;
    }
}


//根据列名和一行数据源获取一行表格<tr>
function getRowByColumnItem(column, rowdata) {
    var content = "";
    content += "<tr>";
    $(column).each(function (i, item) {
        content += "<td>"
        content += rowdata[item];
        content += "</td>"
    });
    content += "</tr>"
    return content;
}
//根据列名和一行数据源获取一列表格<td>
function getColumByIdItem(columnname, rowdata) {
    var content = "";
    content += "<td>"
    content += rowdata[columnname];
    content += "</td>"
    return content;
}


function getUserLableAndRediect() {
    var params = {
        'action': 'getUserFromSession'
    };
    $.post("./handler/LoginHandler.ashx", params, function (data, status) {

        var checked = data.checked;
        var nickname = data.nickname;
        var lable = $(".Lable_username");
        if (checked == 'yes' && nickname.length > 0) {
            lable.html(nickname);
        } else {
        //    window.location = "Login.html"
        }
    }, 'json');
}

getUserLableAndRediect();